home *** CD-ROM | disk | FTP | other *** search
- /*
- #-------------------------------------------------------------------------------------------
- #
- # Program: < DMZ 1.3 >
- # File: < dmzMain.c >
- #
- # by Pete Helme
- # of <Apple Macintosh Developer Technical Support - or wheverever>
- #
- # Modification History
- # 5/27/94 rrk Implemented support for PPC
- # 2/1/94 by Peter Lovell, GE Information Services
- # for Think C 6.0
- # 9/21/92 rrk Implemented ATalk Trans Queue Handler
- #
- # Copyright © 1990 Apple Computer, Inc.
- # All rights reserved.
- #
- #-------------------------------------------------------------------------------------------
- */
-
- #include "dmz.h"
-
- #ifndef _Gestalt
- #define _Gestalt 0xA1AD
- #endif
-
- #ifndef THINK_C
- extern _DataInit();
- #endif
-
-
- /*
- * imported Global Data objects, very expensive.
- */
- extern char gNameGlob[34];
- extern Boolean gLookupFinished;
- extern Boolean gUpdateListFlag;
- extern ListHandle gZonesList, gObjectTypeList;
- extern PacketBuffer gBuffers[kNumBuffers];
-
-
- /*
- * Global Data objects, used by routines external to main().
- */
-
-
- /*
- * gDoneFlag, becomes true when File/Quit chosen.
- */
- Boolean gDoneFlag;
-
- /*
- * gMyDialog, our main dialog.
- */
- DialogPtr gMyDialog; /* main dialog */
-
- /*
- * gLookupDialog, where we can set our preference for lookup times and lookup strings for
- * matching.
- */
- DialogPtr gLookupDialog; /* dialog for NBP lookup prefs */
-
- /*
- * gSortMode is our global sort value.
- */
- long gSortMode;
-
- /*
- * gSortItem is our global sort value for which dialog item should be selected.
- */
- short gSortItem = kObjectID; /* default is the object sleector */
-
- /*
- * gMyEvent is used for external access (from the event loop) to the event record.
- * The main outside client of this guy is use in the list routines.
- */
- EventRecord gMyEvent;
-
- /*
- * GMAC is used to hold the result of a SysEnvirons call. This makes
- * it convenient for any routine to check the environment. (What?!? no use of _Gestalt!?!? "Shuddup.")
- */
- SysEnvRec GMAC; /* set up by Initialize */
-
- /*
- * gATalkFlags is used to track whether AppleTalk variables have been allocated, whether
- * VM is enabled, whether the transition queue handler has been installed, so that on
- * cleanup, the appropriate actions can be taken.
- */
- short gATalkFlags = 0; /* initialized right here */
-
- /*
- * gATQEntry is used to install an AppleTalk Transition Queue Handler so that
- * the program can handle changes to AppleTalk status.
- */
-
- myATQEntry gATQEntry; /* set up by Initialize */
-
- /*
- * gContLookUp is used as a flag to keep track of the state of whether or not we are doing
- * continuous network lookups.
- */
- Boolean gContLookUp = true;
-
- /*
- * GHasWaitNextEvent is set at startup, and tells whether the WaitNextEvent
- * trap is available. If it is false, we know that we must call GetNextEvent.
- */
- Boolean gHasWaitNextEvent; /* set up by Initialize */
-
- /*
- * GInBackground is maintained by our osEvent handling routines. Any part of
- * the program can check it to find out if it is currently in the background.
- */
- Boolean gInBackground; /* maintained by Initialize and DoEvent */
-
- /*
- * gAtalkTransUPP saves the universal procptr to the transition routine. We only
- * want to allocate it once in the init routine, then reuse it as AppleTalk gets
- * turned on. The use of the global var only makes sense is the application is to
- * be AppleTalk safe. That is the user can turn AppleTalk on and off, and DMZ
- * does the right thing to protect itself
- */
- ATalkTransitionEventUPP gAtalkTransUPP; /* appletalk transition queue handler */
-
- /* powerpc stuff */
-
-
- #ifdef GENERATINGCFM
- #ifndef __MWERKS__
- QDGlobals qd; /* quickdraw globals */
- #endif
- #endif
-
- /*
- * The Routines for dmzMain.
- */
-
-
- /*
- * Draws an outline around the particular item in the dialog.
- */
- void DrawBoldItem(WindowPtr whichWindow, short theItem, short whichStrID)
- {
- Rect r;
- short kind;
- Handle h;
- Str255 str;
- FontInfo info;
-
- GetFontInfo(&info);
- GetDialogItem(whichWindow, theItem, &kind, &h, &r);
- TextFace(bold);
- MoveTo(r.left, r.top + info.ascent);
- GetIndString(str, kStringListID, whichStrID);
- DrawString(str);
- TextFace(0);
- }
-
- /*
- * Main dialog handling routines for user item updating. Here we'll update the
- * two lists using _LUpdate and also draw a border around the list rectangles
- * themselves. We're actually drawing across the whole length of the content
- * region and not sure around the rView. This is because the 6.x & older
- * List Managers erase the region where the scoll bar use to be. Since this
- * kinda bites we have to draw something to replace that whole.
- *
- * Notice that the routine has to use Pascal calling conventions.
- */
- pascal void updateUserItems(WindowPtr whichWindow, short theItem)
- {
- GrafPtr savedPort;
- Rect r;
-
- GetPort(&savedPort);
- SetPort(whichWindow);
-
- switch(theItem) {
- case kZoneListID:
- LUpdate((*(**gZonesList).port).visRgn, gZonesList);
- r = (**gZonesList).rView;
- MoveTo(whichWindow->portRect.left, r.top-1);
- LineTo(whichWindow->portRect.right, r.top-1);
- MoveTo(whichWindow->portRect.left, r.bottom);
- LineTo(whichWindow->portRect.right, r.bottom);
- break;
- case kNameTypeListID:
- LUpdate((*(**gObjectTypeList).port).visRgn, gObjectTypeList);
- r = (**gObjectTypeList).rView;
- MoveTo(whichWindow->portRect.left, r.top-1);
- LineTo(whichWindow->portRect.right, r.top-1);
- MoveTo(whichWindow->portRect.left, r.bottom);
- LineTo(whichWindow->portRect.right, r.bottom);
- break;
- case kZoneItemID:
- DrawBoldItem(whichWindow, theItem, kZoneStrID);
- break;
- case kObjectID:
- DrawBoldItem(whichWindow, theItem, kObjectStrID);
- break;
- case kTypeID:
- DrawBoldItem(whichWindow, theItem, kTypeStrID);
- break;
- case kNetID:
- DrawBoldItem(whichWindow, theItem, kNetStrID);
- break;
- case kNodeID:
- DrawBoldItem(whichWindow, theItem, kNodeStrID);
- break;
- case kSocketID:
- DrawBoldItem(whichWindow, theItem, kSktStrID);
- break;
- default:
- break;
- }
- SetPort(savedPort);
- }
-
- /*
- * Generic routine for setting up dialog user items update procedure. Saves us a
- * few bytes by not duplicating the routine for each item.
- */
- void getandSetIt(short whichID)
- {
- Rect r;
- short kind;
- Handle h;
- static UserItemUPP gUpdateUserItemsUPP = nil;
-
- GetDialogItem(gMyDialog, whichID, &kind, &h, &r);
-
- if (gUpdateUserItemsUPP==nil)
- gUpdateUserItemsUPP = NewUserItemProc(updateUserItems);
- SetDialogItem(gMyDialog, whichID, userItem, (Handle) gUpdateUserItemsUPP, &r);
- }
-
- /*
- * For each userItem in the list, we'll call getandSetIt() to set up the
- * update procedure pointer. We'll also set up the port's font & size here.
- */
- void setupUserItems(void)
- {
- GrafPtr savedPort;
-
- GetPort(&savedPort);
- SetPort(gMyDialog);
-
- TextFont(monaco);
- TextSize(9);
-
- getandSetIt(kZoneListID);
- getandSetIt(kNameTypeListID);
- getandSetIt(kZoneItemID);
- getandSetIt(kObjectID);
- getandSetIt(kTypeID);
- getandSetIt(kNetID);
- getandSetIt(kNodeID);
- getandSetIt(kSocketID);
-
- SetPort(savedPort);
- }
-
- /*
- * This sets the value of the lookup item control to on
- */
- void setupLookupItem(void)
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDialogItem(gMyDialog, kDoLookupID, &kind, &h, &r);
- SetControlValue((ControlHandle)h, 1);
- }
-
- /*
- * This changes the current value of the gDoLookUp flag and reflects the state in the
- * control
- */
- void doLookupItem(void)
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDialogItem(gMyDialog, kDoLookupID, &kind, &h, &r);
-
- gContLookUp ^= 1; /* assigns bitwise XOR (changes from on to off and visa versa) */
-
- SetControlValue((ControlHandle)h, (short)gContLookUp);
- }
-
- /*
- * Set the default state of a large window for zooming
- */
- void setWindowStdState(WindowPtr theWindow)
- {
- Rect wRect;
- Point tlP, brP;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theWindow);
-
- /*
- * set the userState - convert coords to globals
- */
- tlP.h = theWindow->portRect.left;
- tlP.v = theWindow->portRect.top;
- brP.h = theWindow->portRect.right;
-
- #ifdef THINK_C
- brP.v = screenBits.bounds.bottom-45;
- #else
- brP.v = qd.screenBits.bounds.bottom-45;
- #endif
-
- LocalToGlobal(&tlP);
- LocalToGlobal(&brP);
-
- wRect.left = tlP.h;
- wRect.top = tlP.v;
- wRect.right = brP.h;
- wRect.bottom = brP.v;
-
- (**(WStateData **) (*(WindowPeek)theWindow).dataHandle).stdState = wRect;
-
- SetPort(savePort);
- }
-
-
- /*
- * Create our one and only dialog from the DLOG resource.
- * If the DLOG resource isn't there, go wash your socks.
- */
- void setUpDialogs(void)
- {
-
- /*
- * make sure there is a 'dctb' resource present so color stuff works!
- */
- gMyDialog = GetNewDialog(kMainDialogID, nil, (WindowPtr) -1);
- gLookupDialog = GetNewDialog(kLookupDialogID, nil, (WindowPtr) -1);
-
- setWindowStdState(gMyDialog);
-
- setupUserItems();
- }
-
- /*
- * This frames the Object, type, etc. items in the main dialog window. This tells the
- * user which item the list is currently sorting on. The box size is based on the
- * size of the text itself and not on the dialog item rectangle size. On a machine which
- * supports color, we'll use RGB value form HiliteRGB for the outline box color. No need
- * for this utlity to use stodgy old black and white if it doesn' t have too.. And it
- * also adds some uniformity to the selection idea since the lists also use HiliteRGB.
- * One thing we do not do with the selection is remove it if window is in background...
- * ...should we to be truley HIG compatible?
- */
- void FrameItem(DialogPtr whichDialog, short whichItem)
- {
- short kind;
- Handle h;
- Rect r;
- PenState ps;
- RGBColor rgb, curRGB;
- unsigned char str[10];
- FontInfo info;
- short strListID;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(whichDialog);
-
- TextFace(bold);
-
- /*
- * unframe old item
- */
- GetDialogItem(whichDialog, gSortItem, &kind, &h, &r);
-
- switch (gSortItem) {
- case kObjectID:
- strListID = kObjectStrID;
- break;
- case kTypeID:
- strListID = kTypeStrID;
- break;
- case kNetID:
- strListID = kNetStrID;
- break;
- case kNodeID:
- strListID = kNodeStrID;
- break;
- case kSocketID:
- strListID = kSktStrID;
- break;
- }
-
- GetIndString(str, kStringListID, strListID);
- GetPenState(&ps);
-
- PenPat(&qd.white);
- GetFontInfo(&info);
- r.right = r.left + StringWidth(str) + 2;
- r.left -= 2;
- r.bottom = r.top;
- r.bottom += info.ascent + info.descent + 2;
- r.top -= 1;
- FrameRect(&r);
- SetPenState(&ps);
-
- /*
- * If Color QD is present, we will change the foreground color to HiliteRGB
- * so that our "selection" frame will match our list's hilites.
- */
- if(GMAC.hasColorQD) {
- BlockMove((Ptr) HiliteRGB,(Ptr) &rgb, sizeof(RGBColor));
- GetForeColor(&curRGB);
- RGBForeColor(&rgb);
- }
-
- /*
- * frame new item
- */
- switch (whichItem) {
- case kObjectID:
- strListID = kObjectStrID;
- break;
- case kTypeID:
- strListID = kTypeStrID;
- break;
- case kNetID:
- strListID = kNetStrID;
- break;
- case kNodeID:
- strListID = kNodeStrID;
- break;
- case kSocketID:
- strListID = kSktStrID;
- break;
- }
-
- GetDialogItem(whichDialog, whichItem, &kind, &h, &r);
- GetIndString(str, kStringListID, strListID);
-
- GetFontInfo(&info);
- r.right = r.left + StringWidth(str) + 2;
- r.left -= 2;
- r.bottom = r.top;
- r.bottom += info.ascent + info.descent + 2;
- r.top -= 1;
- FrameRect(&r);
-
- TextFace(0);
-
- /*
- * Reset foreground color.
- */
- if(GMAC.hasColorQD)
- RGBForeColor(&curRGB);
-
- gSortItem = whichItem;
-
- SetPort(savePort);
- }
-
- /*
- * This is the routine called by _DialogSelect. It handles all userItem events
- * except updating.
- */
- void doModeless(DialogPtr whichDialog, short whichItem)
- {
- if(whichDialog == gMyDialog) {
- switch(whichItem) {
- case kZoneListID: /* 1 */
- doZonesListStuff();
- break;
- case kNameTypeListID: /* 2 */
- doObjectTypeListStuff();
- break;
- case kObjectID:
- gSortMode = sortOnObject;
- FrameItem(whichDialog, whichItem);
- getTypesNamesInZone(gNameGlob);
- break;
- case kTypeID:
- gSortMode = sortOnType;
- FrameItem(whichDialog, whichItem);
- getTypesNamesInZone(gNameGlob);
- break;
- case kNetID:
- gSortMode = sortOnNet;
- FrameItem(whichDialog, whichItem);
- getTypesNamesInZone(gNameGlob);
- break;
- case kNodeID:
- gSortMode = sortOnNode;
- FrameItem(whichDialog, whichItem);
- getTypesNamesInZone(gNameGlob);
- break;
- case kSocketID:
- gSortMode = sortOnSocket;
- FrameItem(whichDialog, whichItem);
- getTypesNamesInZone(gNameGlob);
- break;
- default:
- break;
- }
- }
- }
-
- /*
- * doIdle() Called repeatedly in main event loop for cursor tasks
- * and NBPLookups.
- */
- void doIdle(void)
- {
- SpinTheCursor();
- if(gUpdateListFlag == true) {
- processListUpdate();
- }
- }
-
- /*
- * draws the grow box
- */
- void DrawGrowBox(WindowPtr theWindow)
- {
- Rect r, windowRect;
- GrafPtr tempPort;
-
- /*
- * copy theWindow->portRect into a local rect for efficency.
- * no need to dereference theWindow all the time.
- */
- GetPort(&tempPort);
- SetPort(theWindow);
-
- windowRect = theWindow->portRect;
-
- if(((WindowPeek)theWindow)->hilited) {
- MoveTo(windowRect.right-12, windowRect.bottom-12);
- LineTo(windowRect.right-6, windowRect.bottom-12);
- LineTo(windowRect.right-6, windowRect.bottom-6);
- LineTo(windowRect.right-12, windowRect.bottom-6);
- LineTo(windowRect.right-12, windowRect.bottom-12);
-
- MoveTo(windowRect.right-5, windowRect.bottom-10);
- LineTo(windowRect.right-2, windowRect.bottom-10);
- LineTo(windowRect.right-2, windowRect.bottom-2);
- LineTo(windowRect.right-10, windowRect.bottom-2);
- LineTo(windowRect.right-10, windowRect.bottom-5);
- }
- else {
- SetRect(&r, windowRect.right-17, windowRect.bottom-15,
- windowRect.right, windowRect.bottom);
- EraseRect(&r);
- }
-
- MoveTo(windowRect.right-15, windowRect.bottom);
- LineTo(windowRect.right-15, windowRect.bottom-15);
- MoveTo(windowRect.right-15, windowRect.bottom-15);
- LineTo(windowRect.right, windowRect.bottom-15);
-
- SetPort(tempPort);
- }
-
- /*
- * updates the gSortItem rectangle
- */
- void doUpdate(WindowPtr theWindow)
- {
- RGBColor rgb, curRGB;
-
- if(theWindow == gMyDialog)
- {
- if(GMAC.hasColorQD)
- {
- BlockMove((Ptr) HiliteRGB, (Ptr) &rgb, sizeof(RGBColor));
- GetForeColor(&curRGB);
- RGBForeColor(&rgb);
- }
-
- FrameItem(gMyDialog, gSortItem);
- if(GMAC.hasColorQD)
- RGBForeColor(&curRGB);
- DrawGrowBox(theWindow);
- }
- }
-
-
- /*
- * ShowMainWindowAndSizeIt() opens our main window to the size of our main screen
- * and displays it.
- */
- void ShowMainWindowAndSizeIt(void)
- {
- extern void DoZoomWindow(WindowPtr whichWindow, short partCode);
-
- /*
- * show it…
- */
- ShowWindow(gMyDialog);
-
- /*
- * and resize it.
- */
- /* DoZoomWindow(gMyDialog, inZoomOut); */
- }
-
-
- /*
- * doInitializing() Called at application boot to allocate master pointers,
- * check SysEnvirons() for Mac type, check for WaitNextEvent implementation.
- * and call all other initializing routines.
- */
- void doInitializing(void)
- {
- extern void setupMenus();
- OSErr ignoreError, err;
- short count;
-
- /*
- * Initialization traps
- */
- MaxApplZone();
-
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters();
-
- /*
- * ignore the error returned from SysEnvirons; even if an error occurred,
- * the SysEnvirons glue will fill in the SysEnvRec
- */
- ignoreError = SysEnvirons(sysEnvironsVersion, &GMAC);
- if ( GMAC.machineType < 0 ) /*old machines have...*/
- gHasWaitNextEvent = false; /*no separate trap table; no WaitNextEvent */
- else
- gHasWaitNextEvent = TrapAvailable(_WaitNextEvent);
-
- gInBackground = false;
-
- #ifdef THINK_C
- InitGraf(&thePort);
- #else
- InitGraf(&qd.thePort);
- #endif
-
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- InitDialogs(0L);
-
- /*
- * This next bit of code is necessary to allow the default button of our
- * alert be outlined.
- * Changed to call _EventAvail so that we don't lose some important
- * events.
- */
- for (count = 1; count <= 3; count++) {
- EventAvail(everyEvent, &gMyEvent);
- }
-
- /*
- * make 'em wait
- */
- // set up for the alternative spin cursor
- InitAnimatedCursors(kDMZ_ACUR_ID);
-
- /*
- * setupmenus
- */
- setupMenus();
-
- /*
- * setup the dialog.
- */
- setUpDialogs();
- SetPort(gMyDialog);
-
- /*
- * is VM on
- * this must be determined before calling InitEchoBuffers which gets called from
- * InitAppleTalkVars
- */
- if (IsVMOn())
- gATalkFlags |= (1 << kVMActive);
-
- /*
- * setup the list stuff.
- */
- OpenZonesList();
- OpenObjectTypeList();
-
- /*
- * initialize assorted and sundry variables
- */
- gDoneFlag = false;
- gNameGlob[0] = 0;
- gUpdateListFlag = false;
- gLookupFinished = true;
- gSortMode = sortOnObject;
-
- // allocate memory for our globals
- gATQEntry.globs = NewHandleClear(sizeof(myATQEntry));
- if (gATQEntry.globs == nil)
- {
- BigBadError("\pError allocating memory - Aborting program");
- }
-
- /*
- * setup the appletalk stuff.
- */
- InitAppleTalkVars();
-
- /*
- * install our transition queue handler
- */
- if (LAPMgrExists())
- {
-
- gATQEntry.myA5 = (long)LMGetCurrentA5(); /* get the Current A5 */
-
- gAtalkTransUPP = NewATalkTransitionEventProc(ATalkTransQueue);
- gATQEntry.CallAddr = gAtalkTransUPP;
- err = LAPAddATQ((ATQEntry*)&gATQEntry);
- if (err == noErr)
- {
- gATalkFlags |= (1 << kATQInstalled); /* indicate that the trans queue was installed */
- }
- else
- BigBadError("\pError setting up AppleTalk - Aborting program");
- }
- else
- {
- BigBadError("\pThis program requires AppleTalk version 53 or greater");
- }
-
- /*
- * open the main window & size it to the main screen.
- */
- ShowMainWindowAndSizeIt();
-
- InitCursor();
- }
-
- /*
- * uses predefined value to calculate 'grid height' of list.
- */
- short resizeRectToListCellSize(short height)
- {
- short temp;
-
- height -= 113;
- temp = height % 11;
- height += (113 - temp);
-
- return height;
- }
-
- void resizeWindow(WindowPtr whichWindow, short height)
- {
- short kind;
- Handle h;
- Rect r;
- RgnHandle savedClipRgn, theListMgrSucksRgn;
-
- /*
- * this 'grids' the bottom of the window to the right height to fit the list cell size
- */
- SizeWindow(whichWindow, whichWindow->portRect.right-whichWindow->portRect.left, height, true);
-
- GetDialogItem(gMyDialog, kNameTypeListID, &kind, &h, &r);
-
- savedClipRgn = NewRgn();
- theListMgrSucksRgn = NewRgn();
- GetClip(savedClipRgn);
- SetClip(theListMgrSucksRgn);
-
- r.bottom = whichWindow->portRect.bottom;
- SetDialogItem(gMyDialog, kNameTypeListID, kind, h, &r);
-
- LSize((**gObjectTypeList).rView.right-(**gObjectTypeList).rView.left, (whichWindow->portRect.bottom)-(**gObjectTypeList).rView.top, gObjectTypeList);
-
- SizeControl((**gObjectTypeList).vScroll, (**(**gObjectTypeList).vScroll).contrlRect.right -
- (**(**gObjectTypeList).vScroll).contrlRect.left, (**(**gObjectTypeList).vScroll).contrlRect.bottom -
- (**(**gObjectTypeList).vScroll).contrlRect.top - 15);
-
- SetClip(savedClipRgn);
- DisposeRgn(savedClipRgn);
- DisposeRgn(theListMgrSucksRgn);
-
- /*
- * Erase grow box icon
- */
- SetRect(&r, whichWindow->portRect.right-14, whichWindow->portRect.bottom-15,
- whichWindow->portRect.right, whichWindow->portRect.bottom);
- EraseRect(&r);
- }
-
- /*
- * Check to see if a window belongs to the application. If the window pointer
- * passed was NIL, then it could not be an application window. WindowKinds
- * that are negative belong to the system and windowKinds less than userKind
- * are reserved by Apple except for windowKinds equal to dialogKind, which
- * mean it is a dialog.
- * 1.02 - In order to reduce the chance of accidentally treating some window
- * as an AppWindow that shouldn't be, we'll only return true if the windowkind
- * is userKind. If you add different kinds of windows to Sample you'll need
- * to change how this all works.
- */
-
- Boolean IsAppWindow(WindowPtr window)
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else { /* application windows have windowKinds = userKind (8) */
- windowKind = ((WindowPeek) window)->windowKind;
- return (windowKind == userKind);
- }
- } /*IsAppWindow*/
-
-
- /* Check to see if a window belongs to a desk accessory. */
-
- Boolean IsDAWindow(WindowPtr window)
- {
- if ( window == nil )
- return false;
- else /* DA windows have negative windowKinds */
- return ((WindowPeek) window)->windowKind < 0;
- } /*IsDAWindow*/
-
-
- /* Close a window. This handles desk accessory and application windows. */
-
- /*
- * 1.01 - At this point, if there was a document associated with a
- * window, you could do any document saving processing if it is 'dirty'.
- * DoCloseWindow would return true if the window actually closed, i.e.,
- * the user didn’t cancel from a save dialog. This result is handy when
- * the user quits an application, but then cancels the save of a document
- * associated with a window.
- */
-
- Boolean DoCloseWindow(WindowPtr window)
- {
- if ( IsDAWindow(window) )
- CloseDeskAcc(((WindowPeek) window)->windowKind);
- else if ( window == gLookupDialog ) {
- HideWindow(window);
- }
- return true;
- } /*DoCloseWindow*/
-
-
- /*
- * The USER, let's call him "Bob", has clicked in the zoom box so now he, "Bob", probably expects
- * us to do something about it.
- */
-
- void DoZoomWindow(WindowPtr whichWindow, short partCode)
- {
- WindowPeek wp;
- WStateData **wStateH;
- Rect globalPortRect, theSect, zoomRect;
- GDHandle nthDevice, dominantGDevice;
- long sectArea, greatestArea;
- short bias;
- Boolean sectFlag;
- short windowHeight, windowWidth;
-
- wp = (WindowPeek) whichWindow;
-
- SetPort(whichWindow);
- EraseRect(&whichWindow->portRect);
-
- wStateH = (WStateData **)wp->dataHandle;
-
- if(partCode == inZoomOut) {
- if(GMAC.hasColorQD) {
- /*
- * Get the width of our window for later use.
- */
- windowWidth = whichWindow->portRect.right - whichWindow->portRect.left;
-
- /*
- * window's portRect must be converted to global coordinates... a pain in C...
- */
- globalPortRect = (**(*(WindowPeek)whichWindow).strucRgn).rgnBBox; /*whichWindow->portRect;*/
-
- /*
- pt.h = globalPortRect.left;
- pt.v = globalPortRect.top;
- LocalToGlobal(&pt);
- globalPortRect.left = pt.h;
- globalPortRect.top = pt.v;
-
- pt.h = globalPortRect.right;
- pt.v = globalPortRect.bottom;
- LocalToGlobal(&pt);
- globalPortRect.right = pt.h;
- globalPortRect.bottom = pt.v;
- */
-
- /*
- * Now let's calculate the height of the window's title bar
- */
- bias = (**(*(WindowPeek)whichWindow).contRgn).rgnBBox.top -
- (**(*(WindowPeek)whichWindow).strucRgn).rgnBBox.top - 1;
-
- nthDevice = GetDeviceList();
-
- /*
- * This loop checks the window against all the gdRects in the
- * gDevice list and remembers which gdRect contains the largest
- * portion of the window being zoomed.
- */
- greatestArea = 0;
- while(nthDevice != 0L) {
- sectFlag = SectRect(&globalPortRect, &(**nthDevice).gdRect, &theSect);
- sectArea = (long)(theSect.right - theSect.left) * (theSect.bottom - theSect.top);
- if(sectArea > greatestArea) {
- greatestArea = sectArea;
- dominantGDevice = nthDevice;
- }
- nthDevice = GetNextDevice(nthDevice);
- }
-
- /*
- * We must create a zoom rectangle manually in this case.
- * account for menu bar height as well, if on main device
- */
- if (dominantGDevice == GetMainDevice())
- bias = bias + GetMBarHeight();
-
- /*
- * Now let's set our newly discovered 'zoom' rectangle. 3 is the recommend inset
- * value from the device's boundries.
- */
- SetRect(&zoomRect,(**dominantGDevice).gdRect.left+3,(**dominantGDevice).gdRect.top+bias+3,
- (**dominantGDevice).gdRect.right-3,(**dominantGDevice).gdRect.bottom-3);
-
- /*
- * Set up the WStateData record for this window.
- */
- (**wStateH).stdState = zoomRect;
- windowHeight = zoomRect.bottom-zoomRect.top;
-
- /*
- * Resize the bottom coordinate based on the size of a cell for neatness.
- */
- (**wStateH).stdState.bottom = zoomRect.top + resizeRectToListCellSize(windowHeight);
-
- /*
- * We have a fixed width for our window. Reset it now.
- */
- (**wStateH).stdState.right = (**wStateH).stdState.left + windowWidth;
- }
- else {
- /*
- * We (probably) only have one device so this is all we need to do.
- */
- #ifdef THINK_C
- windowHeight = screenBits.bounds.bottom-7-(**wStateH).stdState.top;
- #else
- windowHeight = qd.screenBits.bounds.bottom-7-(**wStateH).stdState.top;
- #endif
- (**wStateH).stdState.bottom = (**wStateH).stdState.top + resizeRectToListCellSize(windowHeight);
- }
- }
-
- ZoomWindow(whichWindow, partCode, true);
- resizeWindow(whichWindow, (short) (whichWindow->portRect.bottom-whichWindow->portRect.top));
- }
-
- void DoGrowWindow(WindowPtr whichWindow, EventRecord *evt)
- {
- Rect limitRect;
- long newSize;
- GrafPtr savePort;
- short height;
-
- GetPort(&savePort);
-
- #ifdef THINK_C
- limitRect = screenBits.bounds;
- #else
- limitRect = qd.screenBits.bounds;
- #endif
-
- SetPort(whichWindow);
-
- limitRect.right = whichWindow->portRect.right + 1;
- limitRect.left = whichWindow->portRect.right + 1;
- limitRect.top = whichWindow->portRect.top + 203;
-
- newSize = GrowWindow(whichWindow, evt->where, &limitRect);
-
- if(newSize != 0L) {
- /*
- * set to our dialog, erase the content region and re-size the window
- */
- /* SizeWindow(whichWindow, LoWord(newSize), height, true);*/
- height = HiWord(newSize);
- height = resizeRectToListCellSize(height);
- resizeWindow(whichWindow, height);
- }
-
- SetPort(savePort);
- }
-
- void main(void)
- {
- WindowPtr whichWindow;
- DialogPtr whichDialog;
- short whichItem;
- Boolean processIt;
- short partCode;
- EventRecord myEvent;
-
- doInitializing();
-
- for ( ;; ) {
- if (gDoneFlag)
- break; /* from main event loop */
-
- if ( gHasWaitNextEvent )
- /*
- * no sleeping for us...
- */
- processIt = WaitNextEvent(everyEvent, &myEvent, 0L, 0L);
- else {
- SystemTask();
- processIt = GetNextEvent(everyEvent, &myEvent);
- }
-
- /*
- * this checks to make sure we don't pass any cmd key events to the
- * modeless dialog. This must be called even if the event traps
- * return false for text edit idling.
- */
- /*
- if(!((myEvent.what==keyDown)&&(gMyEvent.modifiers & cmdKey))) {
- if (!((gMyEvent.what==keyDown)&&((char)(gMyEvent.message & charCodeMask))>'9')
- &&!((gMyEvent.what==keyDown)&&((char)(gMyEvent.message & charCodeMask))<(char)8)) {
- if(IsDialogEvent(&gMyEvent)) {
- if(DialogSelect(&gMyEvent, &whichDialog, &whichItem))
- doModeless(whichDialog, whichItem);
- }
- }
- }
- */
-
- if(!(myEvent.modifiers & cmdKey)) {
- if(IsDialogEvent(&myEvent)) {
- if(DialogSelect(&myEvent, &whichDialog, &whichItem))
- doModeless(whichDialog, whichItem);
- }
- }
- gMyEvent = myEvent;
-
- /*
- if(IsDialogEvent(&myEvent)) {
- if(DialogSelect(&myEvent, &whichDialog, &whichItem)) {
- if(whichDialog == gMyDialog)
- doModeless(whichDialog, whichItem);
- }
- }
- */
-
- {
- switch (myEvent.what)
- {
- case nullEvent:
- doIdle();
- break;
-
- case mouseDown:
- partCode = FindWindow(myEvent.where, &whichWindow);
- switch (partCode)
- {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
-
- case inMenuBar:
- doCommand(MenuSelect(myEvent.where));
- break;
-
- case inDrag:
- #ifdef THINK_C
- DragWindow(whichWindow, myEvent.where, &screenBits.bounds);
- #else
- DragWindow(whichWindow, myEvent.where, &qd.screenBits.bounds);
- #endif
- break;
-
- case inGoAway:
- if (TrackGoAway(whichWindow, myEvent.where))
- DoCloseWindow(whichWindow); /* we don’t care if the user cancelled */
- break;
-
- case inGrow:
- DoGrowWindow(whichWindow, &myEvent);
- break;
-
- case inContent:
- if(whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
-
- case inZoomIn:
- case inZoomOut:
- if(whichWindow == FrontWindow()) {
- if(TrackBox(whichWindow, myEvent.where, partCode))
- DoZoomWindow(whichWindow, partCode);
- }
- break;
-
- default:
- break;
- }
- break;
-
- case keyDown:
- case autoKey:
- if (gMyDialog == FrontWindow()) {
- if (myEvent.modifiers & cmdKey)
- doCommand(MenuKey(myEvent.message & charCodeMask));
- else if ((myEvent.message & charCodeMask) == kEnterKey
- || (myEvent.message & charCodeMask) == kReturnKey)
- doObjectDoubleClick();
- }
- else if (gLookupDialog == FrontWindow())
- if (myEvent.modifiers & cmdKey)
- doCommand(MenuKey(myEvent.message & charCodeMask));
- break;
-
- case activateEvt:
- if ((WindowPtr) myEvent.message == gMyDialog || (WindowPtr) myEvent.message == gLookupDialog) {
- if (myEvent.modifiers & activeFlag) {
- if ((WindowPtr) myEvent.message == gMyDialog)
- doActivate(gMyDialog);
- DisableItem(GetMenuHandle(editID), 0);
- }
- else {
- if ((WindowPtr) myEvent.message == gMyDialog)
- doDeactivate(gMyDialog);
- if(FrontWindow() != gMyDialog && FrontWindow() != gLookupDialog)
- EnableItem(GetMenuHandle(editID), 0);
- }
- }
- DrawMenuBar();
- break;
-
- case updateEvt:
- /*
- * all our updating is handled by the Dialog Mananger
- * and our userItem update routines.
- */
- doUpdate((WindowPtr) myEvent.message);
- break;
-
- case osEvt:
- switch (myEvent.message >> 24) { /* high byte of message */
- case mouseMovedMessage:
- doIdle(); /* mouse moved is also an idle event */
- break;
- case suspendResumeMessage:
- if ( myEvent.message & resumeMask ) {
- /*
- * resume event received
- * check first whether an ATalk Queue Event has occured
- */
- if (((dmzEntryPtr) *(gATQEntry.globs))->atalkStatusChanged)
- {
- ((dmzEntryPtr) *(gATQEntry.globs))->atalkStatusChanged = false; /* clears the changed bit */
- if (((dmzEntryPtr) *(gATQEntry.globs))->atalkActive)
- {
- InitAppleTalkVars();
- invalidateItem(1);
- }
- else // AppleTalk has become inactive
- {
- ClearZoneCells();
- ClearObjectTypesList();
- tellUserNoZones();
- }
- }
- else
- enableSetSelfSend();
- doActivate(gMyDialog);
- gInBackground = false;
- } else {
- /*
- * suspend event received
- */
- restoreSetSelfSend();
- doDeactivate(gMyDialog);
- gInBackground = true;
- }
- DrawMenuBar();
- break;
- }
- break;
- }/*endsw myEvent.what*/
- }
- }
-
- doCleanUpAndTerminate();
- }
-
- /*
- * Handle any activate routines here. In our case this mean activating the lists and redrawing
- * our grow box.
- */
- void doActivate(WindowPtr theWindow)
- {
- /*
- * Hilites scroll bars and updates scrollbar control max fields with _LActivate(true, ...).
- */
- LActivate(true, gZonesList);
- LActivate(true, gObjectTypeList);
-
- /*
- * this is like really dumb but necessary for ListManager
- * skankiness. It forces the lists's scroll bar's to
- * recalculate & update which is not handled by _LActivate.
-
- LUpdate((*(**gZonesList).port).visRgn, gZonesList);
- LUpdate((*(**gObjectTypeList).port).visRgn, gObjectTypeList);
- */
-
- DrawGrowBox(theWindow);
- }
-
- /*
- *
- */
- void doDeactivate(WindowPtr theWindow)
- {
- /*
- * instead of only calling _LActivate(false, ...), we're going to unhilite
- * the two scroll bars too. _LActivate(false, ...) actually hides the WHOLE
- * scroll bar control, outline and all, which isn't really to Human Interface
- * Guidelines or Pete's Mom's Prairie Home Programming Rules. Besides it
- * looks really silly.
- *
- * If you want to use the LActivate instead substitute the following lines
- * for the HilitControl and the LActivate flag lines.
- * 2/17/90 pvh - forget it. just use the LActivate call instead. toolbox wins.
- */
-
- LActivate(false, gZonesList);
- LActivate(false, gObjectTypeList);
-
- /*
- (**gZonesList).lActive = false;
- (**gObjectTypeList).lActive = false;
- HiliteControl((**gZonesList).vScroll, 255);
- HiliteControl((**gObjectTypeList).vScroll, 255);
- ShowControl((**gZonesList).vScroll);
- ShowControl((**gObjectTypeList).vScroll);
- */
-
- DrawGrowBox(theWindow);
- }
-
- /*
- * Cleanup here. Calls all clean up routines.
- */
- void doCleanUpAndTerminate(void)
- {
- closeUpOurAppleTalk();
- HideWindow(gMyDialog);
- DisposOfMyLists();
- DisposeDialog(gMyDialog);
-
- ExitToShell();
- }
-
- /*
- * Set up the Apple, File, and Edit menus using the MBAR resource.
- * If the MENU resources are missing, we die and find something better to do.
- */
- void setupMenus(void)
- {
- Handle myMenuBar;
-
- myMenuBar = GetNewMBar(128);
- SetMenuBar(myMenuBar);
- DisposeHandle(myMenuBar);
- AppendResMenu(GetMenuHandle(appleID), 'DRVR');
-
- DrawMenuBar();
- }
-
- /*
- * The user has tried to cut, copy or paste into the lookup dialog.
- * We'll try to handle that here.
- */
- void handleLookupDialogEdit(void)
- {
- }
-
-
- /*
- * Process mouse clicks in menu bar
- */
- void doCommand(mResult)
- long mResult;
- {
- int theMenu, theItem;
- Str255 daName;
- GrafPtr savePort;
- extern void showAboutMeDialog();
- extern Boolean gDoneFlag;
- short ignore;
-
- theItem = LoWord(mResult);
- theMenu = HiWord(mResult); /* This is the resource ID */
-
- switch (theMenu) {
- case appleID:
- if (theItem == aboutMeCommand)
- showAboutMeDialog();
- else {
- GetMenuItemText(GetMenuHandle(appleID), theItem, daName);
- GetPort(&savePort);
- ignore = OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case fileID:
- switch (theItem) {
- case lookupCommand:
- ShowWindow(gLookupDialog); /* show lookup prefs window */
- SelectWindow(gLookupDialog);
- break;
- case quitCommand:
- gDoneFlag = true; /* Request exit */
- break;
- default:
- break;
- }
- break;
-
- case editID:
- /*
- * If this is for a 'standard' edit item,
- * run it through SystemEdit first.
- * SystemEdit will return false if it's not a system window.
- */
- if ((theItem <= clearCommand) && SystemEdit(theItem-1)) {
- break;
- }
-
- /*
- * Otherwise, it's my window.
- * and we don't need the Edit menu so boogie...
- */
- if(FrontWindow() == gLookupDialog) {
- SysBeep(1);
- }
- break;
- default:
- break;
-
- } /*endsw theMenu*/
-
- HiliteMenu(0);
- } /* doCommand */
-
-
-
- /*
- * handles "OK" button outlining for our About...& Echo dialogs.
- */
- pascal void aboutDialogOKFrame (WindowPtr theWindow, short itemNo)
- {
- Rect r;
- short kind;
- Handle h;
- PenState ps;
-
- GetPenState(&ps);
- GetDialogItem(theWindow, itemNo, &kind, &h, &r);
- PenSize(3, 3);
- FrameRoundRect(&r, 16, 16);
- SetPenState(&ps);
- }
-
-
- /*
- * these few lines center the about box to the main screen 1/6 of the way from the bottom of the
- * menubar to the bottom of the main screen. so decreeth the great John S.
- * noticed the skilled non-use of "with"
- */
- void centerDialog(WindowPtr theWindow)
- {
- short h, v;
-
- #ifdef THINK_C
- h = (screenBits.bounds.right - screenBits.bounds.left) / 2 - (theWindow->portRect.right - theWindow->portRect.left) / 2;
- v = (screenBits.bounds.bottom - screenBits.bounds.top) - (theWindow->portRect.bottom - theWindow->portRect.top) - GetMBarHeight();
- #else
- h = (qd.screenBits.bounds.right - qd.screenBits.bounds.left) / 2 - (theWindow->portRect.right - theWindow->portRect.left) / 2;
- v = (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - (theWindow->portRect.bottom - theWindow->portRect.top) - GetMBarHeight();
- #endif
- v = (v / 3) + GetMBarHeight();
-
- /*
- * move the window to the right spot & display it & wait around
- */
- MoveWindow(theWindow, h, v, true);
- }
-
- /*
- * Display the About... dialog.
- * Then wait until the OK button is clicked before returning.
- */
- void showAboutMeDialog(void)
- {
- GrafPtr savePort;
- DialogPtr aboutDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit = 0;
- UserItemUPP aboutBoxUPP;
-
- GetPort(&savePort);
- aboutDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
-
- /*
- * set up the userItem proc for the "OK" button outline
- */
- GetDialogItem(aboutDialog, 7, &itemType, &itemHdl, &itemRect);
- aboutBoxUPP = NewUserItemProc(aboutDialogOKFrame);
- SetDialogItem(aboutDialog, 7, userItem, (Handle) aboutBoxUPP, &itemRect);
-
- centerDialog((WindowPtr) aboutDialog);
-
- ShowWindow(aboutDialog);
-
- #ifdef THINK_C
- while(itemHit != OK)
- ModalDialog(0L, &itemHit);
- #else
- while(itemHit != ok)
- ModalDialog(0L, &itemHit);
- #endif
-
- DisposeDialog(aboutDialog);
-
- SetPort(savePort);
-
- #ifdef GENERATINGCFM
- DisposeRoutineDescriptor(aboutBoxUPP);
- #endif
-
- } /* showAboutMeDialog */
-
- void BigBadError(Str255 message)
- {
- short itemHit;
-
- SetCursor(&qd.arrow);
- /* type Str255 is an array in MPW 3 */
- ParamText(message, "\p", "\p", "\p");
- itemHit = Alert(rUserAlert, nil);
- closeUpOurAppleTalk();
- ExitToShell();
- } /* BigBadError */
-
- /* the following code is from IM VI 3-8 which demonstrates how to check for the
- * availability of traps
- */
-
- short NumToolboxTraps(void)
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
- return(0x200);
- else
- return(0x400);
-
- } /* NumToolboxTraps */
-
- TrapType GetTrapType(short theTrap)
- {
- short trapMask = 0x0800;
-
- if (theTrap & trapMask)
- return(ToolTrap);
- else
- return(OSTrap);
-
- } /* GetTrapType */
-
- Boolean TrapAvailable(short theTrap)
- {
- TrapType theType;
-
- theType = GetTrapType(theTrap);
- if (theType == ToolTrap) {
- theTrap &= 0x07FF;
- if (theTrap >= NumToolboxTraps())
- theTrap = _Unimplemented;
- }
- return(NGetTrapAddress(theTrap, theType) != NGetTrapAddress(_Unimplemented, ToolTrap));
- }
-
- /* the following code determines whether VM is active or not
- * returns false if VM is not on or is not available
- * returns true if VM is active
- */
-
- Boolean IsVMOn(void)
- {
- long message;
-
- if (!TrapAvailable((short)_Gestalt))
- return(false); /* if there is no Gestalt, then VM wont be on */
-
- if(Gestalt(gestaltVMAttr, &message))
- return (false);
-
- if (BitTst((Ptr)&message, 31 - gestaltVMPresent))
- return (true);
- else
- return (false);
-
- } /* IsVMOn */
-
-